<template>
  <div>
    <el-container>
      <el-header>
        <span>校园宣讲</span>
      </el-header>
    </el-container>
    <div class="graduate-info">
      <!-- 宣讲会搜索框 -->
      <div>
        <el-input
          type="text"
          auto-complete="off"
          v-model="searchForm.searchParams"
          placeholder="xxxxxx公司"
          style="width: 200px; margin-top: 25px"
        ></el-input>
        <el-button
          type="danger"
          icon="el-icon-search"
          @click="search"
          style="margin-top: 25px; margin-left: 15px"
        ></el-button>
      </div>
      <el-divider></el-divider>
      <div v-for="item in list" :key="item.mid" style="margin-top: 10px">
        <el-descriptions
          class="margin-top"
          :title="item.name"
          :column="3"
          border
        >
          <template slot="extra">
            <el-button type="primary" size="small" @click="openDialog(item)"
              >预约</el-button
            >
          </template>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-monitor"></i>
              宣讲会
            </template>
            {{ item.name }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-location"></i>
              地点
            </template>
            {{ item.location }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-place"></i>
              公司
            </template>
            {{ item.company }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-platform-eleme"></i>
              类型
            </template>
            {{ item.type }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-date"></i>
              宣讲时间
            </template>
            <el-date-picker
              type="datetime"
              v-model="item.time"
              readonly
            ></el-date-picker>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-data-line"></i>
              预计人数
            </template>
            {{ item.numbers }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-finished"></i>
              状态
            </template>
            {{ item.finish }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              <i class="el-icon-info"></i>
              具体描述
            </template>
            {{ item.info }}
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <!-- 弹框 -->
      <el-dialog
        title="填写预约信息"
        :visible.sync="dialogFormVisible"
        :modal="true"
        append-to-body
      >
        <el-form :model="appointmentObj" :inline="true">
          <el-form-item label="手机号码" :label-width="formLabelWidth">
            <el-input
              v-model="appointmentObj.phone"
              autocomplete="off"
              style="width: 200px"
            ></el-input>
          </el-form-item>
          <el-form-item label="qq邮箱" :label-width="formLabelWidth">
            <el-input
              v-model="appointmentObj.email"
              autocomplete="off"
              style="width: 200px"
            ></el-input>
          </el-form-item>
          <el-form-item label="预约场次时间" :label-width="formLabelWidth">
            <el-date-picker
              type="datetime"
              placeholder="选择时间"
              readonly
              v-model="appointmentObj.time"
              style="width: 200px"
            ></el-date-picker>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="appoint">预约</el-button>
        </div>
      </el-dialog>
    </div>
    <el-container>
      <el-footer>
        <div>
          <span>专注于互联网校招</span>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "RecommendGraduatepreach",

  data() {
    return {
      searchForm: {
        searchParams: "",
      },
      list: [],
      appointmentObj: {
        mid: 0,
        hid: 0,
        gid: 0,
        name: "",
        gname: "",
        company: "",
        time: new Date(),
        localtion: "",
        finish: "",
        phone: "",
        email: "",
      },
      dialogFormVisible: false,
      formLabelWidth: "100px",
    };
  },

  mounted() {
    this.loadList();
  },

  watch: {
    "searchForm.searchParams": function (newVal) {
      if (newVal === "") {
        this.loadList();
      } else {
        return;
      }
    },
  },
  methods: {
    search() {
      if (this.searchForm.searchParams === "") {
        this.$message({
          message: "输入框无内容",
          type: "error",
        });
        return;
      }
      this.$axios
        .post("/propaganda/search", this.searchForm)
        .then((res) => {
          if (res.data.result != null) {
            this.list = res.data.result;
          } else {
            return;
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },
    loadList() {
      this.$axios
        .post("/propaganda/loadPropaganda")
        .then((res) => {
          if (res.data.result != null) {
            this.list = res.data.result;
          } else {
            return;
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },

    openDialog(row) {
      this.appointmentObj.mid = row.mid;
      this.appointmentObj.hid = row.hid;
      this.appointmentObj.name = row.name;
      this.appointmentObj.company = row.company;
      this.appointmentObj.time = row.time;
      this.appointmentObj.localtion = row.location;
      this.appointmentObj.finish = row.finish;
      this.dialogFormVisible = true;
    },
    appoint() {
      this.$axios
        .post("/appointment/add", this.appointmentObj)
        .then((res) => {
          var response = res.data.desc;
          if (response === "预约失败") {
            this.$message({
              message: "预约失败",
              type: "error",
            });
            return;
          } else if (response === "预约成功") {
            this.$message({
              message: "预约成功",
              type: "success",
            });
            this.dialogFormVisible = false;
            return;
          } else if (response === "已经预约") {
            this.$message({
              message: "已经预约过了",
              type: "error",
            });
            return;
          }
        })
        .catch((error) => {
          console.log(error);
          this.$message({
            message: "系统错误!!!",
            type: "error",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-header {
  background-color: #409eff;
  color: white;
  line-height: 60px;
}

.el-footer {
  background-color: #409eff;
  color: white;
  line-height: 60px;
}

.el-footer div {
  margin-left: 43%;
}

.graduate-info {
  margin-top: 10px;
  margin-bottom: 10px;
  height: 480px;
  background: whitesmoke;
  /* background-image: url(https://img2.baidu.com/it/u=1704860233,2657475479&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=250);
    background-size: 1355px 480px; */
  overflow: auto;
}
</style>
